home *** CD-ROM | disk | FTP | other *** search
- /* mac_misc.c
- * This module contains several general classes of routines:
- *
- * 1. various routines doing simple char manipulation that are not part of the LSC
- * libraries but that the KA9Q main-line code needs.
- * 2. stubs that the KA9Q package uses, but are not implemented on the Mac. Obviously,
- * there must be no functional requirement for these stubs if we are to just return
- * without action on the Mac.
- * 3. routines to support a linked-list structure to store a series of strings
- * (used by the file search code and by the I/O init code).
- * 4. miscellaneous Macintosh routines (like time-related routines)
- *
- */
-
- #include <stdio.h>
- #include "global.h"
- #include "mac.h"
-
- #include <time.h>
-
- extern struct StdWindowRec *stdiowrec,*logwrec,*trcwrec;
-
-
- /* -----------------------------------------*/
- /* various simple routines needed elsewhere */
- /* -----------------------------------------*/
-
- /*
- * MoveIt: this is like a bcopy, but uses pascal string type
- * of data.
- */
-
- MoveIt(to,from)
- char *to, *from;
- {
- int size;
-
- memset(to, 0, 3);
- to[0] = size = strlen(from);
- if ( size <= 0)
- {
- printf("MoveIt: size <= 0 (%d\n", size);
- return;
- }
- to++;
- while( size-- )
- *to++ = *from++;
- }
-
- /* Determine the size of a Mac memory block on the heap.
- * This is here because we do not have alloc.c in the Mac version.
- */
- long
- blksize(blk)
- char *blk;
- {
- register long *ptr;
- ptr = (long *) (((long) blk) - 8);
- return(((*ptr - 8) - ((*(char *)ptr) & 15)) & 0x00FFFFFF);
- }
-
- /* this search routine is used by the telnet support */
-
- char *memchr(str, chr, cnt)
- char *str;
- char chr;
- int cnt;
- {
- int i;
- char *ptr;
-
- for( ptr = str, i = 0; i < cnt; i++, ptr++) {
- if (*ptr == chr )
- return(ptr);
- }
- return(NULLCHAR);
- }
-
- char *strtac(s1,s2)
- register char *s1,*s2;
- {
- register char *result=s1;
- register int n = strlen(s2);
-
- while (*s1++)
- ;
- while(--s1>=result)
- *(s1+n)= *s1;
- s1++;
- while (*s2)
- *s1++=*s2++;
- return result;
- }
-
-
- /* -----------------------*/
- /* unimplemented routines */
- /* -----------------------*/
-
- /*
- * doshell: execute a shell for the user
- */
-
- doshell()
- {
- printf("SHELL is not implemented.\n");
- }
-
- /* restore: stub */
- restore()
- {}
-
- /* stxrdy: stub */
- stxrdy()
- {return(1);}
-
- /* disable: stub */
- disable()
- {}
-
- /* sysreset: stub */
- sysreset()
- {}
-
- /* ------------------*/
- /* name-list manager */
- /* ------------------*/
-
- /*
- * NLadd_name
- * This routine adds an additional name to a list of structures. A success/failure
- * indication is returned for the caller to examine (0=success, -1=failure).
- */
-
- int NLadd_name(name,first)
- char *name;
- struct RemoveIt *first;
- {
- struct RemoveIt *rptr;
-
- /* get our first entry, traverse list to reach end */
- rptr = first;
- while(rptr->next != NULL ) {
- rptr = rptr->next;
- }
-
- /* allocate space for another list entry */
-
- if ( (rptr->next = (struct RemoveIt *)malloc(sizeof (struct RemoveIt)) ) == NULL) {
- printf("Could not allocate memory for structure RemoveIt\n");
- return(-1);
- }
-
- /* allocate space for the name */
-
- if ( (rptr->name_ptr = malloc(strlen(name)+1) ) == NULL) {
- rptr->next = NULL;
- printf("Could not allocate memory for %s\n", name);
- return(-1);
- }
-
- /* copy the name to the allocated area */
- strcpy(rptr->name_ptr, name);
-
- /* jump to last entry on list and initialize */
- rptr = rptr->next;
- rptr->next = NULL; /* initialize pointer to next entry */
- rptr->name_ptr = NULL; /* initialize string pointer */
-
- return (0); /* return success indication */
- }
-
- /*
- * NLdelete_all
- * This routine deletes all the storage allocated for the list of structures, and leaves
- * the first entry set with a null pointer.
- */
-
- int NLdelete_all(first)
- struct RemoveIt *first;
- {
- struct RemoveIt *rptr;
- struct RemoveIt *next;
-
- /* get our first entry, delete string but leave structure with null pointer */
- rptr = first;
- next = rptr->next;
- if (rptr->name_ptr != NULL)
- (void) free(rptr->name_ptr);
- rptr->next = NULL; /* initialize pointer to next entry */
- rptr->name_ptr = NULL; /* initialize string pointer */
-
- /* now traverse list */
- while(next != NULL) {
- rptr = next;
- next = rptr->next;
- if (rptr->name_ptr != NULL)
- (void) free(rptr->name_ptr);
- (void) free(rptr);
- }
-
- return (0); /* return success indication */
- }
-
- /*
- * NLdelete_first
- * This routine deletes the first entry.
- */
-
- int NLdelete_first(first)
- struct RemoveIt *first;
- {
- struct RemoveIt *rptr;
-
- /* get our first entry, delete string if there is one */
-
- rptr = first->next;
- if (first->name_ptr != NULL)
- (void)free(first->name_ptr); /* delete string */
-
- /* if there are more structures, copy the next one into the first, then
- * delete the storage of the next one */
-
- if (rptr != NULL) {
- first->next = rptr->next; /* copy pointers */
- first->name_ptr = rptr->name_ptr;
- (void)free(rptr); /* delete structure */
- }
-
- return (0); /* return success indication */
- }
-
- /*
- * NLreturn_first
- * This routine returns the string pointer in the first entry.
- */
-
- char *NLreturn_first(first)
- struct RemoveIt *first;
- {
-
- /* get our first entry, return string pointer component */
-
- return(first->name_ptr);
- }
-
- /* -----------------------------*/
- /* environment or time routines */
- /* -----------------------------*/
-
- /*
- * clksec: return the amount of time in secs.
- */
-
- int32
- clksec()
- {
- return(time(NULL));
- }
-
- /* checks the time then ticks and updates ISS */
- static unsigned long tickval = 0;
- void
- check_time()
- {
- if(TickCount() > tickval + 6 )
- {
- tickval = TickCount();
- tick();
- (void)iss();
- (void)icmpclk();
- }
- }
-
- /* get environment: only use within KA9Q is to retrieve the local timezone.
- */
-
- char *getenv(str)
- char *str;
- {
- return(tzname[0]);
- }
-
- char *strsave( p)
- char *p;
- {
- char *t;
-
- t=malloc(strlen(p));
- strncpy(t,p,strlen(p));
- }
-
- void
- MacHelp() /* Enter the Help Facility */
- {
- DoHelp("\p","\pKA9Q Internet Software","\pApple Macintosh Version",
- "\p⌐ Copyright 1988, Phil Karn",TRUE,0L);
- DisposeHelp();
- }
- void
- mac_quits()
- {
- /* Call Mac cleanup routine */
- iostop();
- exit(0);
- }
- void
- mac_windows(item,event)
- char *item;
- EventRecord *event;
- {
- if(strcmp(item,"Console") == 0)
- SelectWindow(stdiowrec);
- if(strcmp(item,"Log") == 0)
- SelectWindow(logwrec);
- if(strcmp(item,"Trace") == 0)
- SelectWindow(trcwrec);
- }
-